import {Component, OnInit, Input, ViewChild} from '@angular/core';

@Component({
    selector: 'orhon-switchtabs',
    templateUrl: './switchtabs.component.html',
    styleUrls: ['./switchtabs.component.scss'],
})
export class SwitchtabsComponent implements OnInit {
    @Input() actions: string[];
    @Input() height = 500;
    @Input() currentIndex?: number;
    @ViewChild('slides', {static: true}) slides;
    slideOpts = {
        initialSlide: 0,
        speed: 100,
        autoHeight: true,
    };
    defaultValue = '0';

    constructor() {
        this.currentIndex = 0;
    }

    ionSlideDidChange() {
        this.slides.getActiveIndex().then((res) => {
            this.defaultValue = String(res);
        });
    }

    segmentChanged(ev: any, val?: number) {
        let item = 0;
        if (val !== undefined) {
            item = val;
        } else {
            item = Number(ev.detail.value);
        }
        const index = item;
        this.currentIndex = index;
        this.slides.slideTo(index).then(res => {
        });
    }

    ngOnInit() {
        this.segmentChanged(1, this.currentIndex);
        this.defaultValue = String(this.currentIndex);
    }
}
